package com.maizhi.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.maizhi.dao.BaseDaoI;
import com.maizhi.dao.impl.Page;
import com.maizhi.service.BaseServiceI;

/**
 * 基础Service,所有ServiceImpl需要extends此Service来获得默认事务的控制
 * 
 */
@Service("baseService")
@Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class BaseServiceImpl<T> implements BaseServiceI<T> {

	BaseDaoI<T> baseDao;
	
	public BaseDaoI<T> getBaseDao() {
		return baseDao;
	}

	@Autowired
	public void setBaseDao(BaseDaoI<T> baseDao) {
		this.baseDao = baseDao;
	}

	public Long count(String hql, Object... param) {
		return baseDao.count(hql, param);
	}

	public Long count(String hql, List<Object> param) {
		return baseDao.count(hql, param);
	}

	public void delete(T o) {
		baseDao.delete(o);
	}

	public Integer executeHql(String hql) {
		return baseDao.executeHql(hql);
	}

	public List<T> find(String hql) {
		return this.baseDao.find(hql);
	}
	
	public List<T> find(String hql, Object... param) {
		return baseDao.find(hql, param);
	}

	public List<T> find(String hql, List<Object> param) {
		return baseDao.find(hql, param);
	}

	public List<T> find(String hql, int page, int rows, List<Object> param) {
		return baseDao.find(hql, page, rows, param);
	}

	public List<T> find(String hql, int page, int rows, Object... param) {
		return baseDao.find(hql, page, rows, param);
	}

	public List findBySql(String sql) {
		return baseDao.findBySql(sql);
	}

	public List findBySql(String sql, int page, int rows) {
		return baseDao.findBySql(sql, page, rows);
	}

	public List findBySql(T t, String sql) {
		return baseDao.findBySql(t, sql);
	}

	public List findBySql(T t, String sql, int page, int rows) {
		return baseDao.findBySql(t, sql, page, rows);
	}

	public T get(Class<T> c, Serializable id) {
		return baseDao.get(c, id);
	}

	public T get(String hql, Object... param) {
		return baseDao.get(hql, param);
	}

	public T get(String hql, List<Object> param) {
		return baseDao.get(hql, param);
	}

	public T load(Class<T> c, Serializable id) {
		return baseDao.load(c, id);
	}

	@Transactional
	public T merge(T o) {
		baseDao.merge(o);	
		return o;
	}

	@Transactional
	public T save(T o) {
		baseDao.save(o);
		return o;
	}

	@Transactional
	public T saveOrUpdate(T o) {
		baseDao.saveOrUpdate(o);
		return o;
	}

	@Transactional
	public T update(T o) {
		baseDao.update(o);
		return o;
	}

	public List<T> findByHqlAndPage(String hql, Object[] values, int min, int max) {
		return baseDao.findByHqlAndPage(hql, values, min, max);
	}

	public List<T> findByHqlAndPage(String hql, Page page) {
		return baseDao.findByHqlAndPage(hql, page);
	}

	public List<T> findByHqlAndPage(String hql, Object[] values, Page page) {
		return baseDao.findByHqlAndPage(hql, values, page);
	}

	public List findBySqlAndPage(String sql, Object[] values, int min, int max) {
		return baseDao.findBySqlAndPage(sql, values, min, max);
	}

	public List<Map> findBySqlAndPageMap(String sql, Object[] values, int min, int max) {
		return baseDao.findBySqlAndPageMap(sql, values, min, max);
	}

	public List<Map> findBySqlAndPageMap(String sql, Page page) {
		return baseDao.findBySqlAndPageMap(sql, page);
	}

	public List<Map> findBySqlAndPageMap(String sql, Object[] values, Page page) {
		return baseDao.findBySqlAndPageMap(sql, values, page);
	}

	public int getHqlCounts(String hql) {
		return baseDao.getHqlCounts(hql);
	}

	public String[] getSqlCols(String sql) {
		return baseDao.getSqlCols(sql);
	}

	public int getSqlCounts(String sql) {
		return baseDao.getSqlCounts(sql);
	}

}
